<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item>
				<el-input v-model="state.queryForm.userName" placeholder="请输入患者姓名" clearable></el-input>
			</el-form-item>
			<el-form-item>
				<el-button @click="getDataList()">查询</el-button>
			</el-form-item>
		</el-form>
		<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%" @selection-change="selectionChangeHandle">
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
			<el-table-column prop="userName" label="患者姓名" header-align="center" align="center"></el-table-column>
			<el-table-column prop="userSex" label="性别" header-align="center" align="center"></el-table-column>
			<el-table-column prop="userAge" label="年龄" header-align="center" align="center"></el-table-column>
			<el-table-column prop="userCard" label="身份证号" header-align="center" align="center"></el-table-column>
			<!-- <el-table-column prop="viewState" label="就诊状态" header-align="center" align="center"></el-table-column>
			<el-table-column prop="startCase" label="初步诊断" header-align="center" align="center"></el-table-column> -->
			<el-table-column prop="userAddr" label="地址" header-align="center" align="center"></el-table-column>
			<!-- <el-table-column prop="registerDept" label="挂号科室" header-align="center" align="center"></el-table-column>
			<el-table-column prop="seeDoctor" label="挂号医生" header-align="center" align="center"></el-table-column> -->
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button type="primary" link @click="BatchHandleView(scope.row)">查看记录</el-button>
				</template>
			</el-table-column>
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button type="primary" link @click="addPatientIn(scope.row)">出院</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>
		<!-- 弹窗, 新增 / 修改 -->
		<AddOrUpdate ref="listUserRef"></AddOrUpdate>
	</el-card>
</template>

<script setup lang="ts" name="SysPostIndex">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import { ElMessage,ElMessageBox} from 'element-plus/es'
import { IHooksOptions } from '@/hooks/interface'
import AddOrUpdate from './housepatientview.vue'
import {usePatientRecordSubmitApi} from '@/api/sys/patientrecord'
const state: IHooksOptions = reactive({
	dataListUrl: '/sys/patientrecord/page',
	deleteUrl: '/sys/patientrecord',
	queryForm: {
		userName: '',
		status:1,
		orgId:localStorage.getItem('org')
	}
})
const listUserRef = ref()
const BatchHandleView=(row:any)=>{
	listUserRef.value.init(row);
}
const addPatientIn=(row:any)=>{
	ElMessageBox.confirm('确定进行出院操作?', '提示', {
			confirmButtonText: '确定',
			cancelButtonText: '取消',
			type: 'warning'
	})
	.then(() => {
		let param={id:row.id,status:2,uid:row.patientId}
		usePatientRecordSubmitApi(param).then(() => {
			ElMessage.success({
				message: '出院成功',
				duration: 500
			})
			getDataList();
		})
	})
	.catch(() => {})
}
const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
